package cn.enzo.utils.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.ServletWebRequest;

public class CommonController<T> {
	public final static String PAGE = "pagehelper";

	public final static String REDIRECT = "redirect:";
	
	
	/**
	 * 得到request
	 * @return   
	 * HttpServletRequest
	 */
	protected HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

		return request;
	}

	/**
	 * 得到response
	 * @return   
	 * HttpServletRequest
	 */
	protected HttpServletResponse getResponse() {
		HttpServletResponse resp = ((ServletWebRequest) RequestContextHolder.getRequestAttributes()).getResponse();
		return resp;
	}
	
	/**
	 * 得到分页的页码 
	 * @return   
	 * Integer
	 */
	protected Integer  getPageSize() {
		String parameter = getRequest().getParameter("pageSize");
		if(null == parameter || "".equals(parameter)){
			return 10;
		}
		return Integer.parseInt(parameter);
	}
	/**
	 * 得到请求的第几页 
	 * @return   
	 * Integer
	 */
	protected Integer getPageNo() {
		String parameter = getRequest().getParameter("pageNum");
		if(null == parameter || "".equals(parameter)){
			return 1;
		}
		return Integer.parseInt(parameter);
	}
}
